package tbdp.tas

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

/**
  * Created by xbkaishui on 17/1/14.
  */
object DataLoad {

  def loadVolRateTrain(dt: String): mutable.HashMap[String, mutable.Map[String, ArrayBuffer[Double]]] = {
    val sql = "select * from (select sCode ,  marketType ,agency1BSVolRateTrain ,yAgency1BSVolRateTrain, tdate , row_number() over (partition by SCode,MarketType order by tdate desc) as od  from tbdp.product_topval where tdate < " + dt + " )t where od <=1 "
    println("tbdp.product_topval sql " + sql)

    val con = Utils.getHiveConn
    // create statement
    val stmt = con.createStatement()
    val res = stmt.executeQuery(sql)
    println(" execute " + sql + " successful")
    val topValMap = new mutable.HashMap[String, mutable.Map[String, ArrayBuffer[Double]]]()
    while (res.next()) {
      val scode = res.getString(1)
      val marketType = res.getString(2)
      val agency1BSVolRateTrain = res.getInt(3)
      val yAgency1BSVolRateTrain = res.getInt(4)
      val result = topValMap.getOrElse(marketType, new mutable.HashMap[String, ArrayBuffer[Double]]())
      val data = new ArrayBuffer[Double]()
      data.append(agency1BSVolRateTrain)
      data.append(yAgency1BSVolRateTrain)
      result.put(scode, data)
      topValMap.put(marketType, result)
    }
    println(" tbdp.product_topval map " + topValMap)

    topValMap
  }

  def main(args: Array[String]) {
    val dt = "20170106"
    loadVolRateTrain(dt)
  }

}
